<?php
class H_View_Helper_Editor extends Zend_View_Helper_FormTextarea{
	const BASIC_TYPE = "BASIC_TYPE";
	const FULL_TYPE = "FULL_TYPE";
	const CUS_TYPE = "CUS_TYPE";
	public function editor($name, $value = null, $attribs = null,$type = null,$urlSampleData = null){
		$baseUrl = BASE_URL;		
		if (!empty($type))
			$type = ",CMS.getToolbar('{$type}')";
		$output = "";	
		$buttonClick="";
		if (!empty($urlSampleData)){			
			$output = "<div>".$this->view->formButton("buttongetsampledata_{$name}", $this->view->t('du lieu mau'), array('rel'=>$urlSampleData))."</div>";
			$buttonClick = "$('#buttongetsampledata_{$name}').click(function(){
                                $.post('{$urlSampleData}',  function(data){
                                    editor_{$name}.setData(data);
                                 });
			});";
		}
		$output = $output . $this->formTextarea($name,$value,$attribs);
		$this->view->headScript()->appendScript("
			var editor_{$name} = CKEDITOR.replace('{$name}'{$type});
			CKFinder.setupCKEditor( editor_{$name}, '{$baseUrl}/jslibrary/ckfinder/');
			{$buttonClick}		
		");
		return $output;
	}
}